package cn.buk.tms.eotms.request;

import cn.buk.common.flight.dto.FlightInfoDto;
import cn.buk.tms.common.dto.base.BasePassengerDto;
import cn.buk.tms.common.dto.flight.BaseFlightOrderDto;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotEmpty;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static cn.buk.common.Constant.*;

/**
 * @author yfdai
 */
public class FlightOrderRequestDto extends BaseFlightOrderDto {

    /**
     * 行程类型+
     */
    private int routeType;

    /**
     * 接口参数
     * 航班信息列表
     */
    @NotEmpty(message = "航班信息不能为空")
    private List<FlightInfoDto> flights;

    /**
     * 接口参数
     * 乘机人信息列表
     */
    @NotEmpty(message = "乘机人信息不能为空")
    private List<BasePassengerDto> passengers;

    /**
     * 接口参数
     * 选择的增值服务产品代码
     */
    private List<String> serviceProductCodes;

    private String itineraryRecipient;

    /**
     * 收件人联系电话
     */
    private String itineraryRecipientMobile;

    /**
     * 是否邮寄
     */
    private int itineraryMailingStatus;

    /**
     * 邮寄备注
     */
    private String itineraryMailingMemo;

    /**
     * 派送日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date deliveryDate;

    private String pnrNo;

    private String pnrDetail;

    /**
     * 出票时限的日期部分
     */
    private Date tktlDate;

    /**
     * 出票时限的时间部分
     */
    private String tktlTime;


    public void calcCost() {
        if (psgCount == 0 && this.passengers != null) {
            for (BasePassengerDto psg: this.passengers) {
                if (psg.isSelected()) {
                    psgCount++;
                }
            }
        }

        if (this.getAdultCount() == 0 && this.getChildCount() == 0 && this.passengers != null) {
            int adultCount = 0;
            int childCount = 0;
            int infantCount = 0;
            for (BasePassengerDto psg : this.passengers) {
                if (!psg.isSelected()) {
                  continue;
                }
                if (psg.getPsgType() == PSG_TYPE_ADU) {
                    adultCount++;
                } else if (psg.getPsgType() == PSG_TYPE_CHD) {
                    childCount++;
                } else if (psg.getPsgType() == PSG_TYPE_INF) {
                    infantCount++;
                }
            }

            setAdultCount(adultCount);
            setChildCount(childCount);
            setInfantCount(infantCount);
        }

        this.calc();
    }

    public List<FlightInfoDto> getFlights() {
        if (flights == null) {
          flights = new ArrayList<>();
        }
        return flights;
    }

    public void setFlights(List<FlightInfoDto> flights) {
        this.flights = flights;
    }

    public List<BasePassengerDto> getPassengers() {
        if (passengers == null) {
          passengers = new ArrayList<>();
        }
        return passengers;
    }

    public void setPassengers(List<BasePassengerDto> passengers) {
        this.passengers = passengers;
    }

    public String getPnrNo() {
        return pnrNo;
    }

    public void setPnrNo(String pnrNo) {
        this.pnrNo = pnrNo;
    }

    public String getPnrDetail() {
        return pnrDetail;
    }

    public void setPnrDetail(String pnrDetail) {
        this.pnrDetail = pnrDetail;
    }



    public int getItineraryMailingStatus() {
        return itineraryMailingStatus;
    }

    public void setItineraryMailingStatus(int itineraryMailingStatus) {
        this.itineraryMailingStatus = itineraryMailingStatus;
    }

    public String getItineraryMailingMemo() {
        return itineraryMailingMemo;
    }

    public void setItineraryMailingMemo(String itineraryMailingMemo) {
        this.itineraryMailingMemo = itineraryMailingMemo;
    }

    public Date getDeliveryDate() {
        return deliveryDate;
    }

    public void setDeliveryDate(Date deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    public Date getTktlDate() {
        return tktlDate;
    }

    public void setTktlDate(Date tktlDate) {
        this.tktlDate = tktlDate;
    }

    public String getTktlTime() {
        return tktlTime == null ? "" : tktlTime.trim();
    }

    public void setTktlTime(String tktlTime) {
        this.tktlTime = tktlTime;
    }

    public String getItineraryRecipient() {
        return itineraryRecipient;
    }

    public void setItineraryRecipient(String itineraryRecipient) {
        this.itineraryRecipient = itineraryRecipient;
    }

    public String getItineraryRecipientMobile() {
        return itineraryRecipientMobile;
    }

    public void setItineraryRecipientMobile(String itineraryRecipientMobile) {
        this.itineraryRecipientMobile = itineraryRecipientMobile;
    }


    public int getPsgCount() {
        return psgCount;
    }

    public void setPsgCount(int psgCount) {
        this.psgCount = psgCount;
    }


    public List<String> getServiceProductCodes() {
        if (serviceProductCodes == null) {
            this.serviceProductCodes = new ArrayList<>();
        }
        return serviceProductCodes;
    }

    public void setServiceProductCodes(List<String> serviceProductCodes) {
        this.serviceProductCodes = serviceProductCodes;
    }

    public int getRouteType() {
        return routeType;
    }

    public void setRouteType(int routeType) {
        this.routeType = routeType;
    }
}
